package com.riaya.controller;

import com.riaya.entity.Detail;
import com.riaya.feign.GoodService;
import com.riaya.model.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: KAIyo
 * @Date: 2025/7/24 15:05
 * @Version: v1.0.0
 * @Description: TODO
 **/
@RestController
@CrossOrigin
public class GoodeController {

    @Autowired
    private GoodService goodService;


    @GetMapping("/All")
    public R getGoodsList(@RequestParam(value = "sortId", required = false) Integer sortId) {
        return goodService.getGoodsList(sortId);
    }

    @PostMapping("/drop")
    public R dropGoods(@RequestBody Detail detail) {
        return goodService.dropGoods(detail);
    }

    @GetMapping("/getsortlist")
    public R getSortList() {
        return R.ok(goodService.getList());
    }

    @GetMapping("/sortgood")
    public R getSortGoods(@RequestParam(value = "sortId",defaultValue = "0") Integer sortId) {
        return goodService.getSortList(sortId);
    }

    @PostMapping("/buy")
    public R buyGoods(@RequestBody Detail detail) {
        goodService.dropGoods(detail);
        return R.ok("","购买成功");
    }

}
